package tcp;

import java.io.IOException;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.nio.charset.StandardCharsets;

/**
 * 客户端
 */
public class TcpClientDemo01 {
    public static void main(String[] args) throws IOException {
        //1、要知道服务端的地址和端口号
        final InetAddress serverIp = InetAddress.getByName("127.0.0.1");
        int port = 9999;

        //2、创建一个socket链接
        final Socket socket = new Socket(serverIp, port);

        //3、发送消息的IO流
        final OutputStream outputStream = socket.getOutputStream();
        outputStream.write("你好2".getBytes(StandardCharsets.UTF_8));

        outputStream.close();
        socket.close();
    }
}
